# 兼容性更好的 CMakeLists.txt - 支持旧版本 CMake
cmake_minimum_required(VERSION 3.0)
project(mBoundsCheck VERSION 1.0.0 LANGUAGES C)

# 设置C标准
set(CMAKE_C_STANDARD 11)
set(CMAKE_C_STANDARD_REQUIRED ON)

# 编译器选项
if(CMAKE_COMPILER_IS_GNUCC OR CMAKE_C_COMPILER_ID MATCHES "Clang")
    set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall -Wextra -O2")
endif()

# 包含目录
include_directories(include)

# 源文件列表
file(GLOB LIB_SOURCES "src/*.c")

# 创建静态库
add_library(bounds_check STATIC ${LIB_SOURCES})

# 创建测试可执行文件
if(EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/test/test_bounds_check.c")
    add_executable(test_bounds_check test/test_bounds_check.c)
    target_link_libraries(test_bounds_check bounds_check)
endif()

# 创建示例可执行文件
if(EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/example.c")
    add_executable(example example.c)
    target_link_libraries(example bounds_check)
endif()

# 安装目标
install(TARGETS bounds_check
    ARCHIVE DESTINATION lib
)

install(FILES include/bounds_check.h
    DESTINATION include
)